package com.rlz.drawable.helper

import android.graphics.drawable.Drawable
import com.rlz.drawable.Shape
import com.rlz.drawable.insetDrawable
import com.rlz.drawable.shapeDrawable

/**
 * Created by RLZ
 * on 2021/5/18
 *
 * 添加几种常用的 背景样式
 */
class Shape {

    companion object {

        /**
         * 圆角矩形
         */
        @JvmStatic
        fun sp(color: Int): Drawable = sp(color, 0f)

        @JvmStatic
        fun sp(color: Int, radius: Float): Drawable =
                shapeDrawable {
                    shape(Shape.RECTANGLE)
                    solid(color)
                    corner(radius = radius)
                }

        /**
         * 带padding的
         */
        @JvmStatic
        fun pd(color: Int, radius: Float, padding: Int): Drawable =
                insetDrawable {
                    drawable = shapeDrawable {
                        corner(radius)
                        solid(color)
                    }
                    setInset(padding)
                }

        /**
         * 圆锥形
         */
        @JvmStatic
        fun oval(color: Int): Drawable {
            return shapeDrawable {
                shape(Shape.RECTANGLE)
                solid(color)
            }
        }

        /**
         * 线型
         */
        @JvmStatic
        fun line(color: Int): Drawable {
            return shapeDrawable {
                shape(Shape.RECTANGLE)
                solid(color)
            }
        }

        /**
         * 渐变色
         * angle 必须为45的倍数
         */
        @JvmStatic
        fun gradient(radius: Float, startColor: Int, endColor: Int): Drawable {
            return gradient(180, radius, startColor, endColor)
        }

        @JvmStatic
        fun gradient(radius: Float, startColor: Int, endColor: Int, centerColor: Int): Drawable {
            return gradient(180, radius, startColor, endColor, centerColor)
        }

        @JvmStatic
        fun gradient(angle: Int, radius: Float, startColor: Int, endColor: Int): Drawable {
            return shapeDrawable {
                corner(radius)
                gradient(angle, startColor, endColor)
            }
        }

        @JvmStatic
        fun gradient(angle: Int, radius: Float, startColor: Int, endColor: Int, centerColor: Int): Drawable {
            return shapeDrawable {
                corner(radius)
                gradient(angle, startColor, endColor, centerColor)
            }
        }


        /**
         * 边框 内部透明 圆形
         */
        @JvmStatic
        fun stroke(color: Int, width: Float): Drawable {
            return shapeDrawable {
                shape(Shape.OVAL)
                solid(android.R.color.transparent)
                stroke(color, width)
            }
        }

        /**
         * 边框  矩形或圆角矩形
         */
        @JvmStatic
        fun stroke(radius: Float, color: Int, width: Float): Drawable {
            return shapeDrawable {
                shape(Shape.RECTANGLE)
                corner(radius)
                solid(android.R.color.transparent)
                stroke(color, width)
            }
        }
    }
}